<?php
	## global
	global $wpdb,$paged,$current_page,$mn_chothue,$mn_canban,$mn_kygui,$mn_gioithieu,$mn_lienhe,$mn_quydinhsudung;
	
	if(!session_id())
	{
	 	session_start();
	}	
	$sesionID = session_id();
	require_once(ABSPATH . WPINC . '/registration.php'); 
	require_once(ABSPATH . WPINC . '/ms-functions.php');
	require_once(ABSPATH . "wp-admin" . '/includes/file.php');
	require_once(ABSPATH . "wp-admin" . '/includes/image.php');
	require_once(ABSPATH . "wp-admin" . '/includes/media.php');
	
	## thietlap cac bien global
	// luu cac hoat dong vua qua
	$_SESSION[$sesionID]['current-views'] = array();
	
	//luu cac hoat dong timkiem
	$_SESSION[$sesionID]['current-searchs'] = null;
	
	set_time_limit(900);	
	@ini_set("memory_limit","80M");
	add_theme_support('menus');
	
	## Define
	define("WP_MYSITE_URL",get_bloginfo('home') );
	define("WP_MYSITE_NAME", get_bloginfo('name'));
	define("WP_MYSITE_DESCRIPTION", get_bloginfo('description'));
	define("WP_MYSITE_STYLESHEET_URL", get_bloginfo('stylesheet_url'));
	define("WP_MYSITE_ADMIN_EMAIL", get_bloginfo('admin_email'));
	define("WP_MYSITE_CHARSET", get_bloginfo('charset'));
	define("WP_MYSITE_TEMPLATE_URL", get_bloginfo('template_url'));
	
	## index
	include TEMPLATEPATH.'/admins/index.php';
	
	## subscriber
	//include TEMPLATEPATH.'/incs/subscriber/instal_data.php';
	
	## Modifys
	include TEMPLATEPATH.'/modifys/remove-defaults.php';
	include TEMPLATEPATH.'/modifys/modify-defaults.php';
	include TEMPLATEPATH.'/modifys/modify-menu.php';
	include TEMPLATEPATH.'/modifys/support.php';
    include TEMPLATEPATH .'/incs/myfunctions.php';
   	## email
	include TEMPLATEPATH.'/mails/smtp.php';	
	
	## Meta Box
	//include TEMPLATEPATH .'/incs/metaboxs/meta-box-3.2.2.class.php';
	//include TEMPLATEPATH .'/incs/metaboxs/meta-box.php';
	
	//include TEMPLATEPATH .'/incs/metaboxs/index.php';
		
	//include TEMPLATEPATH .'/incs/metaboxs/custom-metaboxes-page/example-functions.php';
	//include TEMPLATEPATH .'/incs/metaboxs/custom-metaboxes-page/init.php';
	
	## Taxonomy Box
	include TEMPLATEPATH .'/incs/taxonomyboxs/taxonomy-meta.php';
	include TEMPLATEPATH .'/incs/taxonomyboxs/taxonomy-meta-usage.php';
	require_once TEMPLATEPATH.'/incs/resize_image.php';
	//include TEMPLATEPATH .'/incs/taxonomyboxs/simple-term-meta.php';
	//include TEMPLATEPATH .'/incs/taxonomyboxs/simple-term-meta-usage.php';
	
	## incs
	//include TEMPLATEPATH .'/incs/analytics.php';
	include TEMPLATEPATH .'/incs/breadcrums.php';
	include TEMPLATEPATH .'/incs/page-nav.php';
	
	include TEMPLATEPATH .'/incs/seos/vietnamese-slug.php';
	include TEMPLATEPATH .'/incs/seos/search-engine-optimization.php';
	include TEMPLATEPATH .'/incs/soluongtruycap.php';    
	
	include TEMPLATEPATH .'/incs/metaboxs/index.php';
	## post meta
	include TEMPLATEPATH .'/postmetas/custom-post.php';
	include TEMPLATEPATH .'/postmetas/custom-taxonomy.php';
	
	## orders
	//include TEMPLATEPATH .'/orders/index.php';
	## Payment
	//require_once TEMPLATEPATH .'/incs/payments/paypal/payment_db.php';
	//require_once TEMPLATEPATH .'/incs/payments/paypal/payments.php';
	//require_once TEMPLATEPATH .'/incs/payments/paypal/paypal.php';
	
	### filters
	include TEMPLATEPATH .'/filters/filters.php';
	
	## rewrite
	include TEMPLATEPATH .'/rewrites/remove-category-slug.php';
	include TEMPLATEPATH .'/rewrites/add-html.php';
	
	## post_tag for page
	/*
	$current_user = wp_get_current_user();
	
	$myrole = wp_get_user_roles_by_user_id( $current_user->ID );
	$usermeta = get_the_author_meta( 'add_user_role', $current_user->ID );
	//print_r($current_user);
	//print_r($myrole);
	
	if($myrole[0]=="administrator" && ($current_user->user_login=="admin" || $current_user->user_login=="dbthanhbinh"))
	{
		//include TEMPLATEPATH .'/admins/controller-admin.php';
	}
	*/	
	
	add_action('init', 'db_tindaluu');
	function db_tindaluu()
	{	
		global $wpdb;
		$tindaluu 		= $wpdb->prefix . "tindaluu";
				
		if ($wpdb->get_var("SHOW TABLES LIKE '$tindaluu'") != $tindaluu)
		{
			$wpdb->query("CREATE TABLE {$tindaluu}
			(			
				ID  mediumint(10) AUTO_INCREMENT PRIMARY KEY ,
				postID 			INT  NULL,
				userID		 	INT  NULL,
				date	 		DATETIME							
			)ENGINE=MyISAM DEFAULT CHARSET=utf8");
		}	
		
	}